﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Observer_Pattern
{
    class StockObserver : IObserver
    {
        private double ibmPrice;
        private double aaplPrice;
        private double googPrice;

        private static int observerIDTracker = 0;
        private int observerID;
        private Subject stockGrabber;

        public StockObserver(Subject stockGrabber)
        {
            this.stockGrabber = stockGrabber;
            this.observerID = ++observerIDTracker;

            stockGrabber.attach(this);
        }

        public void update(double ibmPrice, double aaplPrice, double googPrice)
        {
            this.ibmPrice = ibmPrice;
            this.aaplPrice = aaplPrice;
            this.googPrice = googPrice;

            printThePrices();
        }

        public void printThePrices()
        {
            Console.WriteLine("[" + observerID + "]: IBM - " + ibmPrice + " | AAPL - " + aaplPrice + " | GOOG - " + googPrice);
        }
    }
}
